package ThreadDemo;

public class syn {
    public static void main(String[] args) {
        Table t = new Table();
        Thread thread = new Thread() {
            @Override
            public void run() {
                while (true) {
                    Thread thread = Thread.currentThread();
                    System.out.println(thread.getName() + ":" + t.b());
                }
            }
        };
        Thread thread1 = new Thread() {
            @Override
            public void run() {
                while (true) {
                    Thread thread = Thread.currentThread();
                    System.out.println(thread.getName() + ":" + t.b());
                }
            }
        };

        thread.start();
        ;
        thread1.start();
    }
}

class Table {
    private int a = 5;

    public int b() {
        if (a == 0) {
            throw new RuntimeException("错误");
        }
        return a--;
    }
}
